import 'dart:convert' show json;

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }

  return null;
}

class FundMNFInfo {
  FundMNFInfo({
    this.datas,
    this.errCode,
    this.success,
    this.errMsg,
    this.message,
    this.errorCode,
    this.errorMessage,
    this.errorMsgLst,
    this.totalCount,
    this.expansion,
  });

  factory FundMNFInfo.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<MNFItem> datas = jsonRes['Datas'] is List ? <MNFItem>[] : null;
    if (datas != null) {
      for (final dynamic item in jsonRes['Datas']) {
        if (item != null) {
          datas.add(MNFItem.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }
    return FundMNFInfo(
      datas: datas,
      errCode: asT<int>(jsonRes['ErrCode']),
      success: asT<bool>(jsonRes['Success']),
      errMsg: asT<Object>(jsonRes['ErrMsg']),
      message: asT<Object>(jsonRes['Message']),
      errorCode: asT<String>(jsonRes['ErrorCode']),
      errorMessage: asT<Object>(jsonRes['ErrorMessage']),
      errorMsgLst: asT<Object>(jsonRes['ErrorMsgLst']),
      totalCount: asT<int>(jsonRes['TotalCount']),
      expansion: Expansion.fromJson(asT<Map<String, dynamic>>(jsonRes['Expansion'])),
    );
  }

  List<MNFItem> datas;
  int errCode;
  bool success;
  Object errMsg;
  Object message;
  String errorCode;
  Object errorMessage;
  Object errorMsgLst;
  int totalCount;
  Expansion expansion;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'Datas': datas,
        'ErrCode': errCode,
        'Success': success,
        'ErrMsg': errMsg,
        'Message': message,
        'ErrorCode': errorCode,
        'ErrorMessage': errorMessage,
        'ErrorMsgLst': errorMsgLst,
        'TotalCount': totalCount,
        'Expansion': expansion,
      };
  @override
  String toString() {
    return json.encode(this);
  }
}

class MNFItem {
  MNFItem({
    this.fCODE,
    this.sHORTNAME,
    this.pDATE,
    this.nAV,
    this.aCCNAV,
    this.nAVCHGRT,
    this.gSZ,
    this.gSZZL,
    this.gZTIME,
    this.nEWPRICE,
    this.cHANGERATIO,
    this.zJL,
    this.hQDATE,
    this.iSHAVEREDPACKET,
    this.img,
  });

  factory MNFItem.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : MNFItem(
          fCODE: asT<String>(jsonRes['FCODE']),
          sHORTNAME: asT<String>(jsonRes['SHORTNAME']),
          pDATE: asT<String>(jsonRes['PDATE']),
          nAV: asT<String>(jsonRes['NAV']),
          aCCNAV: asT<String>(jsonRes['ACCNAV']),
          nAVCHGRT: asT<String>(jsonRes['NAVCHGRT']),
          gSZ: asT<String>(jsonRes['GSZ']),
          gSZZL: asT<String>(jsonRes['GSZZL']),
          img: asT<String>(jsonRes['img']),
          gZTIME: asT<String>(jsonRes['GZTIME']),
          nEWPRICE: asT<String>(jsonRes['NEWPRICE']),
          cHANGERATIO: asT<String>(jsonRes['CHANGERATIO']),
          zJL: asT<String>(jsonRes['ZJL']),
          hQDATE: asT<String>(jsonRes['HQDATE']),
          iSHAVEREDPACKET: asT<bool>(jsonRes['ISHAVEREDPACKET']),
        );

  String fCODE;
  String sHORTNAME;
  String pDATE;
  String nAV;
  String aCCNAV;
  String nAVCHGRT;
  String gSZ;
  String gSZZL;
  String gZTIME;
  String nEWPRICE;
  String cHANGERATIO;
  String zJL;
  String hQDATE;
  String img;
  bool iSHAVEREDPACKET;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'FCODE': fCODE,
        'SHORTNAME': sHORTNAME,
        'PDATE': pDATE,
        'NAV': nAV,
        'ACCNAV': aCCNAV,
        'NAVCHGRT': nAVCHGRT,
        'GSZ': gSZ,
        'GSZZL': gSZZL,
        'img': img,
        'GZTIME': gZTIME,
        'NEWPRICE': nEWPRICE,
        'CHANGERATIO': cHANGERATIO,
        'ZJL': zJL,
        'HQDATE': hQDATE,
        'ISHAVEREDPACKET': iSHAVEREDPACKET,
      };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Expansion {
  Expansion({
    this.gZTIME,
    this.fSRQ,
  });

  factory Expansion.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Expansion(
          gZTIME: asT<String>(jsonRes['GZTIME']),
          fSRQ: asT<String>(jsonRes['FSRQ']),
        );

  String gZTIME;
  String fSRQ;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'GZTIME': gZTIME,
        'FSRQ': fSRQ,
      };
  @override
  String toString() {
    return json.encode(this);
  }
}
